package io.vector.study.designpattern.factory.simple;

import io.vector.study.designpattern.factory.simple.impl.AddOperator;
import io.vector.study.designpattern.factory.simple.impl.DivisionOperator;
import io.vector.study.designpattern.factory.simple.impl.MultiOperator;
import io.vector.study.designpattern.factory.simple.impl.SubtractOperator;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by vector on 2017/3/20.
 */
public class SimpleOperatorFactory {

    private static final Map<String, BinaryOperator> operatorMap = new HashMap<>();

    private SimpleOperatorFactory() {

    }

    static {
        registerOperator(new AddOperator());
        registerOperator(new MultiOperator());
        registerOperator(new SubtractOperator());
        registerOperator(new DivisionOperator());
    }

    public static void registerOperator(BinaryOperator operator) {
        operatorMap.put(operator.getOperatorName(), operator);
    }

    public static BinaryOperator getOperator(String operatorName) {
        return operatorMap.get(operatorName);
    }

}
